

const Cu = Components.utils;
function require(url) {
    let scope = {};
    Cu.import(url, scope);
    return scope;
}
let {Dialogs} = require("chrome://jsm/content/Dialogs.js");
let {OS} = require("resource://gre/modules/osfile.jsm");

function saveMacro(action) {
    if(!("arguments" in window) || !window.arguments.length)
        return;

    let title = "iMacros";
    Dialogs.browserForFileSave(title, window.arguments[0].filename)
        .then((path) => {
            return OS.File.writeAtomic(
                path, window.arguments[0].code, 
                {encoding: "utf-8"}
            );
        }).catch(e => Components.utils.reportError(e));
}



window.onload = function () {
    if("arguments" in window && window.arguments.length > 0) {
        var textbox = document.getElementById("viewfield");
        textbox.value = window.arguments[0].code;
    }
};

